package com.ludaxu.google.holder;

import com.ludaxu.google.R;
import com.ludaxu.google.adapter.DefaultAdapter;
import com.ludaxu.google.tools.UiUtils;

import android.view.View;
import android.widget.RelativeLayout;

public class MoreHolder extends BaseHolder<Integer> {
	public static final int HAS_NO_MORE = 0;// 没有额外数据
	public static final int LOAD_ERROR = 1;// 加载失败
	public static final int HAS_MORE = 2;// 有额外数据
	private RelativeLayout rl_more_loading, rl_more_error;

	/**
	 * 当holder显示的时候,显示什么样子
	 */
	@Override
	public View initView() {
		View view = UiUtils.inflate(R.layout.load_more);
		rl_more_loading = (RelativeLayout) view
				.findViewById(R.id.rl_more_loading);
		rl_more_error = (RelativeLayout) view.findViewById(R.id.rl_more_error);
		return view;
	}

	@Override
	public View getContentView() {
		loadMore();
		return super.getContentView();
	}

	private DefaultAdapter adapter;

	public MoreHolder(DefaultAdapter adapter) {
		super();
		this.adapter = adapter;
	}

	private void loadMore() {
		// 请求服务器 加载下一批数据 加到listview
		// 交给adapter 让adapter加载更多数据
		adapter.loadMore();

	}

	/**
	 * 根据数据做界面的修改
	 */
	@Override
	public void refreshView(Integer data) {
		if (data==LOAD_ERROR) {
			rl_more_error.setVisibility(View.VISIBLE);
		}else {
			rl_more_error.setVisibility(View.INVISIBLE);
		}
		rl_more_loading.setVisibility(data==HAS_MORE?View.VISIBLE:View.GONE);

	}

}
